package cn.keniykey.mc.landterritory.landflag.flag;

import java.util.Arrays;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import cn.keniykey.mc.landterritory.event.LandTerritoryReloadConfigEvent;
import cn.keniykey.mc.landterritory.land.api.Land;
import cn.keniykey.mc.landterritory.landflag.api.ELandFlagParType;
import cn.keniykey.mc.landterritory.landflag.api.ELandFlagType;
import cn.keniykey.mc.landterritory.landflag.api.ILandFlagAuthority;
import cn.keniykey.mc.landterritory.landflag.api.JavaLandFlag;
import cn.keniykey.mc.landterritory.landflag.api.LandFlagConfigurationFile;
import cn.keniykey.mc.landterritory.landflag.api.LandFlagListenerManager;
import cn.keniykey.mc.landterritory.landflag.api.LandFlagSetting;
import cn.keniykey.mc.landterritory.toolkit.Util;

public final class FlagAdminFlag extends JavaLandFlag implements Listener,ILandFlagAuthority{
	
	@Override
	public ELandFlagType getELandFlagType() {
		return ELandFlagType.PLAYER;
	}
	@Override
	public ELandFlagParType getELandFlagParType() {
		return ELandFlagParType.MUCH;
	}
	@Override
	public boolean allowAllPlayerData() {
		return true;
	}
	
	@Override
	public void onEnable() {
		LandFlagListenerManager.registerListener(this, this);
		LandFlagSetting.setFlagAuthority(this, this);
	}
	
	@EventHandler
	public void onConfigReload(final LandTerritoryReloadConfigEvent e) {
		final LandFlagConfigurationFile config = this.getLandFlagConfigurationFile();
		if(!config.has()) {
			config.set("name", "&c标记总权");
			config.set("lore", Arrays.asList("&8（标记参数内的玩家拥有其它普通标记的许可权限）","&c（高风险标记，请谨慎添加）"));
		}
		this.setDisplayName(Util.conver(config.getString("name")));
		this.setIntroductionLore(Util.conver(config.getStringList("lore")));
	}
	
	@Override
	public boolean hasFlagPermissions(Player player, Land land) {
		return JavaLandFlag.hasLandFlagParameter(land, this, player);
	}
}